﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace 窗体计算器
{
    public partial class Form1 : Form
    {   
        double value1, value2;//两个输入值
        string operation;//运算符
        double result;
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
          
        
        //计算
        private void button5_Click_1(object sender, EventArgs e)
        {
            int count = 0;
            value2 = Convert.ToDouble(textBox1.Text);
            switch (operation)
            {
                case "+":
                    result = value1 + value2; break;
                case "-":
                    result = value1 - value2; break;
                case "*":
                    result = value1 * value2; break;
                case "/":
                    if (value2 != 0)
                    { result = value1 / value2; break; }
                    else
                    {
                        MessageBox.Show("除数不能为0！");
                        break;
                    }

            }
            textBox1.Text = result.ToString();

        }
        
        //数据的清除
        private void button7_Click_1(object sender, EventArgs e)
        {
            textBox1.Text = "";
        }        //数字按键

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            operation = "-";
            value1 = Convert.ToDouble(textBox1.Text);
            textBox1.Text = "";
        }

        private void num7_Click_1(object sender, EventArgs e)
        {
            textBox1.Text += "7";
        }

        private void num8_Click_1(object sender, EventArgs e)
        {
            textBox1.Text += "8";
        }

        private void num9_Click(object sender, EventArgs e)
        {
            textBox1.Text += "9";
        }

        private void num4_Click(object sender, EventArgs e)
        {
            textBox1.Text += "4";
        }

        private void num5_Click(object sender, EventArgs e)
        {
            textBox1.Text += "5";
        }

        private void num6_Click(object sender, EventArgs e)
        {
            textBox1.Text += "6";
        }

        private void num1_Click(object sender, EventArgs e)
        {
            textBox1.Text += "1";
        }

        private void num2_Click(object sender, EventArgs e)
        {
            textBox1.Text += "2";
        }

        private void num3_Click(object sender, EventArgs e)
        {
            textBox1.Text += "3";
        }

        private void button6_Click(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            operation = "*";
            value1 = Convert.ToDouble(textBox1.Text);
            textBox1.Text = "";
        }
        private void button1_Click_1(object sender,EventArgs e)
        {
            operation = "+";
            value1 = Convert.ToDouble(textBox1.Text);
            textBox1.Text = "";
        }

        private void button4_Click(object sender, EventArgs e)
        {
            operation = "/";
            value1 = Convert.ToDouble(textBox1.Text);
            textBox1.Text = "";
        }

        private void num0_Click(object sender, EventArgs e)
        {
            textBox1.Text += "0";
        }




    }
}




        






